<style type="text/css">
    .action-cell {
        margin-bottom: 20px;
    }

    .search-block {
        display: flex;
        margin-bottom: 10px;
    }

    .input-search {
        margin-right: 10px;
    }
</style>
<template>
    <div>
        <div class="action-cell">
            <!--<div class="search-block">-->
            <!--<Input v-model="value" class="input-search" placeholder="根据标题查找" style="width: 200px"></Input>-->
            <!--<Input v-model="value" class="input-search" placeholder="根据标题查找" style="width: 200px"></Input>-->
            <!---->
            <!--<Button type="ghost" icon="ios-search">搜索</Button>-->
            <!--</div>-->
            <Button type="error" @click="jumpPage('','FinanceAdd')" >添加</Button>
        </div>
        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
        <div style="margin: 10px;overflow: hidden;">
            <div style="float: right;">
                <Page :total="total" size="large" show-total :current="current" show-elevator show-sizer
                      @on-change="changePage"></Page>
            </div>
        </div>
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                images: [],
                updateId:'',
                apiUtilBase: apiUtil.urls.baseUrl,
                tableColumns: [
                    {
                        title: '标题',
                        key: 'Title',
                        align: 'center',

                    },
                    {
                        title: '副标题',
                        key: 'Subtitle',
                        align: 'center',
                    },
                    {
                        title: '封面',
                        align: 'center',
                        key: 'Faceimgurl',
                        render: (h, params) => {
                            return h('div', [
                                h('img', {
                                    attrs: {
                                        src: apiUtil.urls.baseUrl + params.row.Faceimgurl
                                    },
                                    style: {
                                        width: '80px',
                                    },
                                    on: {
                                        click: () => {
                                            this.preview(params.index);
                                        }
                                    }
                                }),
                            ])
                        }
                    },
                    {
                        title: '浏览量',
                        key: 'Viewcount',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 220,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            'margin-right': '10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.jumpPage(params.row.Id,'FinanceEdit')
                                            }
                                        }
                                    }, '编辑'),
                                    h('Button', {
                                        props: {
                                            type: 'success',
                                            size: 'small'
                                        },
                                        style: {
                                            'margin-right': '10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.jumpPage(params.row.Id,'FinanceDetail')
                                            }
                                        }
                                    }, '详情'),
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            'margin-right': '10px',
                                        },
                                        on: {
                                            click: () => {
                                                console.log("轮播id：",params.row.Id);
                                                this.remove(params.row.id)
                                            }
                                        }
                                    }, '删除')
                                ]
                            )
                        }
                    },
                ]
            }
        },
        mounted() {
            this.mockTableData();
        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                let route='';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }
                this.$router.push(route);
            },
            //图片预览
            preview(index) {
                console.log('进入tip预览__index', index);
                this.$imagePreview({
                    images: this.apiUtilBase + this.images,
                    index: index,
                })
            },
            mockTableData() {
                let that = this;

                let para = {
                    current: this.current,
                    limit: 7,
                    type:2,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that,apiUtil.urls.FinanceList, para, function (res) {
                    that.$Loading.finish();
                    that.total = res.Msg.TotalCount;
                    that.current = res.Msg.CurrentPage;
                    that.tableData = res.Msg.Arrays;

                    console.log('tableData:', res)

                    that.tableData.forEach(function (item, i) {
                        that.images.push(that.apiUtilBase + item.faceimgurl);
                        console.log("图片:",that.images)
                    });
                });

            },
            remove(index) {
                let that = this;
                this.$Modal.confirm({
                    title: '删除新闻',
                    content: `是否删除此新闻`,
                    onOk: function () {
                        this.$Loading.start();
                        let para = {id: index};
                        let params = that.$qs.stringify(para);
                        apiUtil.post(that,apiUtil.urls.FinanceDelete, params, function (res) {

                            that.mockTableData();
                        });
                    }
                })
            },
            changePage(row) {
                // 这里直接更改了模拟的数据，真实使用场景应该从服务端获取数据
                console.log("row", row);
                this.current = row;
                this.images = [];
                this.mockTableData();
            }
        },
    }
</script>